
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>简单个人页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <style>
        .simplePerson {
            text-align: center;
            color: #7A786F;
            padding-top: 50px;
            padding-bottom: 110px;
            background-color: #E8E6E8;
        }

        .mymenu {
            margin: 15px auto;
        }

        .mymenu i {
            margin-right: 20px;
        }
    </style>

    <script type="text/javascript">
        $(function () {
            // 获取存放在sessionStorage中的用户信息并转为json对象
            var userJsonStr = sessionStorage.getItem('user');
            var user = JSON.parse(userJsonStr);
            console.log(user);
            // 渲染数据
            if (user){
                $(".simplePerson").renderValues(user);
            } else {
                location.href = "/login.html";
            }

            // 登录注销
            $("#logout").click(function () {
                $.ajax({
                    url:"/sessions",
                    type:"DELETE",
                    success:function () {
                            // 先删除本地的session, 再跳转界面
                            sessionStorage.removeItem('user');
                            window.parent.location.reload();
                    }
                });
            });

            // 跳转到个人页面
            $("#profiles").click(function () {
                window.parent.location.href = $("#profiles").data("url");
            })

            //发送ajax请求获取未阅读的系统消息
            $.ajax({
                url: "/users/"+user.id+"/notice/number",
                type: "GET",
                success: function (data) {
                    $("#systemNoticeNumber").html(data);
                }
            });
        });
    </script>
</head>

<body>
<div class="simplePerson">
    <img class="rounded-circle" width="20%" render-src="headImgUrl">
    <p><strong render-html="nickName"></strong></p>
    <p render-html="email"></p>
    <hr>
    <div class="mymenu">
        <i class="fa fa-user fa-2x fa-fw"></i>
        <a data-url="/mine/profiles.html" role="button" id="profiles">我的</a>
    </div>
    <div class="mymenu">
        <i class="fa fa-bell fa-2x fa-fw"></i>
        <a href="javascript:">信息</a>
    </div>
    <div class="mymenu">
        <i class="fa fa-comment fa-2x fa-fw"></i>
        <a href="/mine/systemContent.html">通知</a>
        <span class="badge badge-danger badge-pill" id="systemNoticeNumber"></span>
    </div>
    <div class="mymenu">
        <i class="fa fa-cog fa-2x fa-fw"></i>
        <a data-url="/mine/info.html" href="javascript:">设置</a>
    </div>
    <hr style="margin-top: 50px;">
    <div class="mymenu" id="logout">
        <i class="fa fa-sign-out fa-2x fa-fw"></i>
        <label>退出登录</label>
    </div>
</div>
</body>
</html>